package com.example.demo.controller;

import com.example.demo.dao.UserMapper;
import com.example.demo.model.UserInfo;
import com.example.demo.service.UserService;
import com.example.demo.service.UserService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-13
 * Time: 16:27
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserService2 userService2;

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/insert")
    @Transactional
    public int insert() {
        // 这里构造一个测试用例
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername("张三");
        userInfo.setPassword("666");

        // 自己先调用
        userMapper.insert(userInfo);
        System.out.println("自己调用");
        // 调用 service 接口
//        int result = userService.insert(userInfo);
//        System.out.println("嵌套1调用");

        try {
            userService2.insert2(userInfo);
            System.out.println("嵌套2调用");
        } catch (Exception e) {
            e.printStackTrace();
        }



        return 1;
    }

}
